//
// Created by Administrator on 2021/5/18.
//
#include <vector>
#include <queue>
#include <iostream>

using namespace std;

class Solution {
public:
    int lastStoneWeight(vector<int> &stones) {
        priority_queue<int> pq; // 默认大堆顶  less<>
        for (auto &x:stones) pq.push(x);
        while (pq.size() >= 2) {
            int a = pq.top();
            pq.pop();
            int b = pq.top();
            pq.pop();
            if (a == b) continue;
            else pq.push(a - b);
        }
        return pq.empty()?0:pq.top();
    }
};

int main() {
    vector<int> v1{2, 7, 4, 1, 8, 1};
    Solution solution;
    cout << solution.lastStoneWeight(v1) << endl;
    return 0;
}